
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <fcntl.h>
#include <io.h>

#include "pio.h"
#include "prottype.h"

void pyank(int fh,long adr,char *file)
{
    FILE *fp;
    long len;
    size_t l;
    
    if((fp = fopen (file,"rb")) == NULL){
	printf("open error %s\n",file);
	return ;
    }

    fseek(fp,0L,2);
    len = ftell(fp);
    rewind(fp);

    while(len) {
	printf(".");
	l = (len>TMPSIZE)? TMPSIZE:len;
	fread(buf.c,1,l,fp);
	pio_apokep(fh,adr,(long)l/2,buf.s);
	len -= l;
	adr += l/2;
    }
    printf("done\n");
    fclose(fp);
}

#ifdef TEST
void main(int ac,char *av[])
{
    int fh;
    long addr,len;
   
    if((fh = open("PCFXPIO$",O_RDWR|O_BINARY))<0) {
	printf("cant open \'pcfxpio.sys\'\n");
	return;
    }

    buf.c = malloc(TMPSIZE);
    if( buf.c == NULL ) {
	printf("malloc error\n");
	close(fh);
	return ;
    }

    addr = 0x0000L;

    if(ac>1) {
	if(ac>2) sscanf(av[2],"%lx",&addr);
	pyank(fh,addr,av[1]);
    }

    close(fh);
    return ;
}
#endif
/* EOF */
